package com.angel.kuaidi.net;

import java.io.IOException;
import java.io.InputStream;

public class AgentInputStream {
	private InputStream mInputStream;

	private boolean mStat; // 是否需统计流量

	private int mFlow; // 过往流量

	public AgentInputStream(InputStream inputStream) {
		mInputStream = inputStream;
		mStat = true;
		mFlow = 0;
	}

	public AgentInputStream(InputStream inputStream, boolean stat) {
		mInputStream = inputStream;
		mStat = stat;
		mFlow = 0;
	}

	public InputStream getImpl() {
		return mInputStream;
	}

	public int read(byte[] b, int offset, int length) throws IOException {
		int ret = mInputStream.read(b, offset, length);

		// 流量统计
		if (mStat)
			mFlow += ret;

		return ret;
	}

	public int getFlow() {
		return mFlow;
	}

	public void close() throws IOException {
		mInputStream.close();
	}
}
